package com.dfd.common.po;

import lombok.Data;

/**
 * 响应给前端的Response业务数据模型
 *
 */
@Data
public class ResponseVo<T> {
    public static final Integer SUCCESS_CODE = 0;
    private static final String SUCCESS_MESSAGE = "success";
    private Integer code;
    private String message;
    private T data;

    public ResponseVo() {

    }

    public ResponseVo(Integer code, String message) {
        this.code = code;
        this.message = message;
    }


    public ResponseVo(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static ResponseVo success() {
        return new ResponseVo(SUCCESS_CODE, SUCCESS_MESSAGE);
    }

    public static <T> ResponseVo<T> success(T data) {
        ResponseVo<T> vo = new ResponseVo<>();
        vo.setCode(SUCCESS_CODE);
        vo.setMessage(SUCCESS_MESSAGE);
        vo.setData(data);
        return vo;
    }

    public static <T> ResponseVo<T> error(Integer co, String msg) {
        ResponseVo<T> vo = new ResponseVo<>();
        vo.setCode(co);
        vo.setMessage(msg);
        vo.setData(null);
        return vo;
    }

    public static <T> ResponseVo<T> error(String msg) {
        ResponseVo<T> vo = new ResponseVo<>();
        vo.setCode(500);
        vo.setMessage(msg);
        vo.setData(null);
        return vo;
    }

}
